package com.fengze.shop.utils;

import com.fengze.shop.dao.MenuDao;
import com.fengze.shop.dao.impl.MenuDaoImpl;
import com.fengze.shop.domain.Menu;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016-11-21.
 */
public class MenuUtils {

    private static MenuDao menuDao = DaoFactory.getInstance()
            .createDao("com.fengze.shop.dao.impl.MenuDaoImpl", MenuDaoImpl.class);

    private static Map<Integer, List<Menu>> menuLs = null;

    private MenuUtils() {}

    static {
        menuLs = getMenuDetail(menuDao.queryMenu(0), 0, new LinkedHashMap<Integer, List<Menu>>());
    }

    public static Map<Integer, List<Menu>> getMenuLs() {
        return menuLs;
    }

    private static Map<Integer, List<Menu>> getMenuDetail(List<Menu> ls, Integer menuId, Map<Integer, List<Menu>> map) {
        map.put(menuId, ls);

        for (Menu menu : ls) {
            getMenuDetail(menuDao.queryMenu(menu.getId()), menu.getId(), map);
        }

        return map;
    }

}
